﻿from django.shortcuts import render, HttpResponse


# Create your views here.
def index(request):
    '''首页

    准备工作
    '''
    markdown = """# 正则路由参数的传递和接收

## 示例

链接|说明
---|---
[/123](/2/123456)<br/>|全数字
[/Dabao666](/2/Dabao666)|字母或下划线开头,数字结尾

## 配置路由

```python
from django.urls import path, re_path
from . import views

urlpatterns = [
    path('', views.index, name='index'),                     # 首页
    re_path('(^\d+$)', views.re_handler, name='re'),         # 全数字
    re_path('(^\w+.*\d+$)', views.user_handler, name='re'),  # 字母或下划线开头, 数字结尾
]
```

## 配置视图

```pyhton
from django.shortcuts import render, HttpResponse
def re_handler(request, Number):
    return HttpResponse(
        '{0}'
        .format(
            Number
        )
        )


def user_handler(request, Uname):
    return HttpResponse(
        '你好: {0}'
        .format(
            Uname
        )
        )
```

"""
    context = {
        'title': 'Home',
        'markdown': markdown,
    }
    return render(request, 'marked.html', context)


def re_handler(request, Number):
    return HttpResponse(
        '{0}'
        .format(
            Number
        )
        )


def user_handler(request, Uname):
    return HttpResponse(
        '你好: {0}'
        .format(
            Uname
        )
        )
